﻿using System.Collections.Generic;
using System.Linq;
using NHibernate.Criterion;

namespace NHibData.Repository
{
    /// <summary>
    /// Base interface for the repository
    /// </summary>
    public interface IRepository<T> where T:BaseEntity
    {
        /// <summary>
        /// Find domain object by ID
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns>Founded domain object</returns>
        T FindById(int id);

        /// <summary>
        /// Find all domain objects
        /// </summary>        
        /// <returns></returns>
        IList<T> FindAll();

        /// <summary>
        /// Returns all data in compliance with given criteria
        /// </summary>
        /// <param name="criteria">Criteria</param>
        /// <returns>results</returns>
        IList<T> FindAll(DetachedCriteria criteria);

        /// <summary>
        /// Save new domain object
        /// </summary>
        /// <param name="t">domain object</param>
        void SaveNew(T t);
       
        /// <summary>
        /// Update domain object
        /// </summary>
        /// <param name="t"></param>
        void Update(T t);

        /// <summary>
        /// Save new domain object
        /// </summary>
        /// <param name="t">domain object</param>
        void SaveOrUpdate(T t);

        /// <summary>
        /// Delete domain object
        /// </summary>
        /// <param name="t">Domain object</param>
        void Delete(T t);


        IQueryable<T> Linq { get; }
    }
}